home *** CD-ROM | disk | FTP | other *** search
/ PC/CD Gamer UK 127 / CD Gamer Issue 127 (October 2003) (Disc 1).ISO / Utilities / Game Shadow 1.6 / gameshadow.exe / ddpopit.js < prev    next >
Encoding:
JavaScript  |  2003-07-04  |  2.4 KB  |  83 lines

  1. //Pop-it menu- By Dynamic Drive
  2. //For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
  3. //This credit MUST stay intact for use
  4.  
  5. function showmenu(e,which){
  6.     if (!document.all&&!document.getElementById&&!document.layers)
  7.         return;
  8.     
  9.     clearhidemenu();
  10.     
  11.     menuobj = document.all.popmenu;
  12.     menuobj.thestyle = menuobj.style;
  13.     
  14.     menuobj.innerHTML = which;
  15.     
  16.     menuobj.contentwidth = menuobj.offsetWidth;
  17.     menuobj.contentheight = menuobj.offsetHeight;
  18.     eventX = event.clientX;
  19.     eventY = event.clientY;
  20.     
  21.     //Find out how close the mouse is to the corner of the window
  22.     var rightedge = document.body.clientWidth - eventX;
  23.     var bottomedge = document.body.clientHeight - eventY;
  24.     
  25.     //if the horizontal distance isn't enough to accomodate the width of the context menu
  26.     //if (rightedge<menuobj.contentwidth)
  27.     //move the horizontal position of the menu to the left by it's width
  28.     menuobj.thestyle.left = document.body.scrollLeft+eventX-menuobj.contentwidth - 4;
  29.     //else
  30.     //position the horizontal position of the menu where the mouse was clicked
  31.     //menuobj.thestyle.left = document.body.scrollLeft+eventX;
  32.     
  33.     //same concept with the vertical position
  34.     if (bottomedge < menuobj.contentheight)
  35.         menuobj.thestyle.top = document.body.scrollTop + eventY - menuobj.contentheight;
  36.     else
  37.         menuobj.thestyle.top = document.body.scrollTop + event.clientY;
  38.     
  39.     // force set position
  40.     //menuobj.thestyle.left = 330;
  41.     //menuobj.thestyle.top = 20;
  42.     menuobj.thestyle.visibility="visible"
  43.     
  44.     return false
  45. }
  46.  
  47. function hidemenu(){
  48.     if (window.menuobj)
  49.         menuobj.thestyle.visibility = "hidden";
  50. }
  51.  
  52. function dynamichide(e){
  53.     if (!menuobj.contains(e.toElement))
  54.         hidemenu();
  55. }
  56.  
  57. function delayhidemenu(){
  58.     delayhide = setTimeout("hidemenu()", 500);
  59. }
  60.  
  61. function clearhidemenu(){
  62.     if (window.delayhide)
  63.         clearTimeout(delayhide);
  64. }
  65.  
  66. function highlightmenu(e,state){
  67.     if (document.all)
  68.         source_el = event.srcElement;
  69.     else if (document.getElementById)
  70.         source_el = e.target;
  71.     if (source_el.className=="menuitems"){
  72.         source_el.id = (state == "on")?"mouseoverstyle":"";
  73.     } else {
  74.         while(source_el.id != "popmenu"){
  75.             source_el = document.getElementById?source_el.parentNode:source_el.parentElement;
  76.             if (source_el.className == "menuitems"){
  77.                 source_el.id = (state == "on")?"mouseoverstyle":"";
  78.             }
  79.         }
  80.     }
  81. }
  82.  
  83. document.onclick = hidemenu;